/**
 * 选择js模块文件窗口，编辑菜单时使用
 */
define(function(){
	var SelectJsModuleWindow = Ext.extend(Ext.Window, {
		title: '选择js模块',
		layout: 'fit',
		resizable: false, modal: true,
		width: cu.getWinWidth(300), 
		height: cu.getWinHeight(350),
	    animateTarget: cu.getDefaultAnimateTarget(),
        bodyStyle:'padding:3px;',
		iconCls: 'icon-window',
		initComponent: function(){
			Ext.apply(this, {
				items:[
					this.treePanel = this.createTreePanel()
				],
				buttons: [
					{text: '确定', width:60, handler: this.ok, iconCls: 'icon-ok', scope: this, disabled: true},
					{text: '取消', width:60, handler: this.close, iconCls: 'icon-close', scope: this}
				],
				listeners:{
					
				}
			});
			SelectJsModuleWindow.superclass.initComponent.call(this);
		},
		createTreePanel: function(){
			return new Ext.tree.TreePanel({
		        collapsible: false,
		        width: 280,
		        margins:'0 0 3 3',
		        autoScroll: true,
		        split: true,
		        dataUrl: 'sys/menu/getJsModules.do',
		        root: {id: '/', expanded: true, listeners:{
		        	expand: function(node){ //默认展开第一层节点
		            	node.eachChild(function(n){n.expand();});
	        		}
	        	}},
		        rootVisible: false,
		        listeners: {
		        	click: function(node){
		        		this.buttons[0].setDisabled(!node.isLeaf());
		        		node.toggle();
		        	},
		        	dblclick: function(node){
		        		if (node.isLeaf){
		        			this.ok();
		        		}
		        	}, scope: this
		        }
			});
		},
		ok: function(){
			var node = this.treePanel.getSelectionModel().getSelectedNode();
			if (!node || !node.isLeaf()){
				return;
			}
			this.callback.call(this.cbScope, node.id.replace(/\//g, '.'));
			this.close();
		}
	});
	return SelectJsModuleWindow;
});